#估计是这个固件库不行，他并不支持蓝牙，官网提供了许多的固件库，这是最新的，失去了蓝牙，好可惜啊
#有人解决的话，记得联系陈振峰同志，QQ：2108469807
from machine import Pin
import os
import bluetooth

bt=bluetooth.Bluetooth()
bt.active(True)
bt.advertise(100,'ESP32_BLE_01')

led=Pin(2,Pin.OUT)
led.value(0)

tx=bluetooth.Characteristis('6E400002-B5A3-F393-E0A9-E50E24DCCA9E',bluetooth.FLAG_READ|bluetooth.FLAG_NOTIFY)
rx=bluetooth.Characteristis('6E400003-B5A3-F393-E0A9-E50E24DCCA9E',bluetooth.FLAG_WRITE)
s = bt.add_service('6E400001-B5A3-F393-E0A9-E50E24DCCA9E', [tx, rx])

def callback(char,data):
    print("Get command:",data)
    if(data==b'0'):
        led.value(0)
        print("LED OFF")
        tx.write("LED IS OFF NOW!\r\n")
    if(data==b'1'):
        led.value(1)
        print("LED ON")
        tx.write("LED is ON Now!\r\n")
rx.on_updata(callback)